﻿using Abp;
using Abp.Castle.Logging.Log4Net;
using Abp.Prism;
using Castle.Facilities.Logging;
using Prism.Ioc;
using SNX.TestTool.ViewModels;
using SNX.TestTool.Views;
using System;
using System.IO;
using System.Windows;

namespace SNX.TestTool
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : PrismApplication
    {
        private readonly AbpBootstrapper _bootstrapper;
        private MainWindow _mainWindow;

        public App()
        {
            _bootstrapper = AbpBootstrapper.Create<SNXTestToolModule>();

            // Load test modules
            var moduleDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules");
            if (Directory.Exists(moduleDirectory))
            {
                _bootstrapper.PlugInSources.Add(new Abp.PlugIns.FolderPlugInSource(moduleDirectory));
            }

            _bootstrapper.IocManager.IocContainer.AddFacility<LoggingFacility>(f => f.UseAbpLog4Net().WithConfig("log4net.config"));
            _bootstrapper.Initialize();
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        protected override Window CreateShell()
        {
            _mainWindow = Container.Resolve<MainWindow>();
            return _mainWindow;
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            //containerRegistry.RegisterForNavigation<MainWindow, MainWindowViewModel>();
        }

        protected override void OnExit(ExitEventArgs e)
        {
            _bootstrapper.IocManager.Release(_mainWindow);
            _bootstrapper.Dispose();
        }
    }
}
